package com.fangyahao.role.service.impl;

import com.fangyahao.role.bean.UserBean;
import com.fangyahao.role.dao.UserDao;
import com.fangyahao.role.service.UserService;
import com.fangyahao.role.utils.DaoFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserServiceImpl implements UserService {

    private UserDao dao;


    @Override
    public Map<String,Object> loginByPhoneAndPassword(String phone,String password) {
        Map<String,Object> rs =new HashMap<>();

        if(phone==null||password==null){
            rs.put("code",404);
            return rs;
        }
        DaoFactory<UserDao> daoFactory = new DaoFactory<>();
        dao = daoFactory.getDao(UserDao.class);
        UserBean userBean = new UserBean();
        userBean.setPhone(phone);
        userBean.setPassword(password);
        UserBean user = dao.selectUser(userBean);
        if(user==null){
            rs.put("code",404);
        }else{

            rs.put("code",200);
            rs.put("userId",user.getId());

        }

        return rs;
    }
}
